package com.ctgu.controller;


import com.ctgu.common.ResponseResult;
import com.ctgu.model.entity.Admin;
import com.ctgu.model.entity.LoginUser;
import com.ctgu.service.IAdminService;
import io.swagger.models.auth.In;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 管理员表 前端控制器
 * </p>
 *
 * @author yiMa
 * @since 2023-07-05
 */
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private IAdminService adminService;

    @GetMapping("/info")
    //管理员
    @PreAuthorize("@AYM.hasAuthority('admin:info:query')")
    public ResponseResult info(){;
        return new ResponseResult<>(200,"成功",SecurityContextHolder.getContext().getAuthentication());
    }

    @PutMapping("/companyStatus")
    //超级管理员
    @PreAuthorize("@AYM.hasAuthority('company:status:update')")
    public ResponseResult updateCompanyStatus(Integer id,String status){
        return adminService.updateCompanyStatus(id,status);
    }

    @PutMapping("/employeeStatus")
    //超级管理员
    @PreAuthorize("@AYM.hasAuthority('employee:status:update')")
    public ResponseResult updateEmployeeStatus(Integer id,String status){
        return adminService.updateEmployeeStatus(id,status);
    }

    @DeleteMapping("/deleteCompany")
    //超级管理员
    @PreAuthorize("@AYM.hasAuthority('company:one:delete')")
    public ResponseResult deleteCompany(Integer id){
        return adminService.deleteCompany(id);
    }

    @DeleteMapping("/deleteEmployee")
    //超级管理员
    @PreAuthorize(("@AYM.hasAuthority('employee:list:delete')"))
    public ResponseResult deleteEmployee(@RequestBody Integer[] ids){
        return adminService.deleteEmployee(ids);
    }

    @PutMapping("/updateAdmin")
    //超级管理员
    @PreAuthorize(("@AYM.hasAuthority('admin:info:update')"))
    public ResponseResult updateAdmin(@RequestBody Admin admin){
        return adminService.updateAdminInfo(admin);
    }
}

